package com.resource.authoritymanage.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.resource.authoritymanage.config.UserPrivilegeEnum;
import com.resource.authoritymanage.entity.TIdentifyRecordEntity;
import com.resource.authoritymanage.service.TIdentifyRecordService;
import com.resource.common.utils.AppResponse;
import com.resource.common.utils.PageUtils;
import com.resource.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.applet.AppletResourceLoader;

import javax.servlet.http.HttpServletResponse;


/**
 * 用户授权记录表
 *
 * @author zkx
 * @email 1486664603@qq.com
 * @date 2023-03-06 20:53:55
 */
@RestController
@RequestMapping("/authority/tidentifyrecord")
public class TIdentifyRecordController {
    @Autowired
    private TIdentifyRecordService tIdentifyRecordService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = tIdentifyRecordService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        TIdentifyRecordEntity tIdentifyRecord = tIdentifyRecordService.getById(id);
        return R.ok().put("tIdentifyRecord", tIdentifyRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TIdentifyRecordEntity tIdentifyRecord) {
        //默认只有游客权限
//        if(tIdentifyRecord.getId()==null) {
//            tIdentifyRecord.setUserPrivilege(UserPrivilegeEnum.CONSUMER_PRIVILEGE.getCode());
//        }
        tIdentifyRecord.setIsApply("否");
        tIdentifyRecordService.save(tIdentifyRecord);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TIdentifyRecordEntity tIdentifyRecord) {
        tIdentifyRecordService.updateById(tIdentifyRecord);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        tIdentifyRecordService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    @GetMapping("/export")
    public R exportData(HttpServletResponse response){
        return tIdentifyRecordService.exportData(response);
    }


    @PostMapping("/import")
    public R  importData(@RequestParam("file") MultipartFile file){
        R r= tIdentifyRecordService.importData(file);
        return R.ok();
    }

}
